package com.ysg.binding.viewadapter;

import android.widget.ImageView;
import androidx.databinding.BindingAdapter;

import com.makeramen.roundedimageview.RoundedImageView;
import com.ysg.utils.YImageUtil;
import com.ysg.utils.YStringUtil;


public final class ImageViewAdapter {
    @BindingAdapter(value = {"url", "placeholderRes", "iconRes"}, requireAll = false)
    public static void setImageUri(ImageView imageView, String url, int placeholderRes, int iconRes) {
        if (iconRes != 0) {
            imageView.setImageResource(iconRes);
        }

        if (YStringUtil.isNotEmpty(url)){
            YImageUtil.show(imageView, url);
        }
    }

    @BindingAdapter(value = {"url"}, requireAll = false)
    public static void setImageUri(RoundedImageView imageView, String url) {
        if (YStringUtil.isNotEmpty(url)){
            YImageUtil.show(imageView, url);
        }
    }

}

